//
//  HMOrderDetailViewController.m
//  HMSupplier
//
//  Created by haohao on 2017/7/6.
//  Copyright © 2017年 haohao. All rights reserved.
//

#import "HMOrderDetailViewController.h"
#import "HMDetailOrderTableViewCell.h"
#import "HMTypeOfOrderTableViewCell.h"
#import "TodayOrder.h"
#import "HMOrderCenterTool.h"
#import "OrderCenterOrderDetail.h"
@interface HMOrderDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *myTableView;

NS_STRONG NSArray *dataArray;

@end

@implementation HMOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setSubView];
}

- (void)setSubView {
    _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWidthSCREEN, KHeightSCREEN) style:UITableViewStyleGrouped];
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    _myTableView.separatorColor = [UIColor clearColor];
    self.title = _model.item_name;
    [self.view addSubview:_myTableView];
    
    [self getData];
}

- (void)getData {
    [HMOrderCenterTool getOrerDetailWithid:_model success:^(NSArray *dataArray) {
        _dataArray = dataArray;
        [_myTableView reloadData];
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _dataArray.count + 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        HMDetailOrderTableViewCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"HMDetailOrderTableViewCell" owner:self options:nil] firstObject];
        cell.model = _model;
        return cell;
    } else {
        HMTypeOfOrderTableViewCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"HMTypeOfOrderTableViewCell" owner:self options:nil] firstObject];
        cell.model = _dataArray[indexPath.section - 1];
        return cell;
    }
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 95;
    } else {
        return 60;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001;
}

@end
